const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const StudyProgress = sequelize.define('StudyProgress', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  user_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: 'users',
      key: 'id'
    }
  },
  day_number: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '第几天的学习内容（1-54）'
  },
  stage: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '第几阶段（1-4）'
  },
  title: {
    type: DataTypes.STRING(200),
    allowNull: false,
    comment: '学习内容标题'
  },
  is_completed: {
    type: DataTypes.BOOLEAN,
    defaultValue: false
  },
  completed_at: {
    type: DataTypes.DATE,
    allowNull: true
  },
  study_time_minutes: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '学习时间（分钟）'
  },
  notes: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '学习笔记'
  },
  homework_status: {
    type: DataTypes.ENUM('not_started', 'in_progress', 'completed', 'reviewed'),
    defaultValue: 'not_started'
  },
  homework_content: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '作业内容/提交内容'
  }
}, {
  tableName: 'study_progress',
  indexes: [
    {
      unique: true,
      fields: ['user_id', 'day_number']
    },
    {
      fields: ['user_id', 'stage']
    }
  ]
});

module.exports = StudyProgress; 